package com.hsgene.authority.dto;

import com.hsgene.common.util.http.HttpRequestUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.Map;

/**
 * 客户请求信息
 *
 * @author wangbing
 * @version 1.0, 2018/11/9
 */
public class ClientRequestDto implements Serializable {

    private static final long serialVersionUID = -1696008585197482123L;

    private ClientRequestApi api;

    private Map<String, String> headers;

    private Map<String, String> params;

    public ClientRequestDto() {
    }

    public ClientRequestDto(HttpServletRequest request) {
        String requestMethod = request.getMethod();
        String requestURI = request.getRequestURI();
        this.api = buildApi(requestURI, requestMethod);
        this.headers = HttpRequestUtils.getHeaders2Map(request);
        this.params = HttpRequestUtils.getParamters2Map(request);
    }

    public ClientRequestApi buildApi(String uri, String method) {
        return new ClientRequestApi(uri, method);
    }

    public ClientRequestApi getApi() {
        return api;
    }

    public void setApi(ClientRequestApi api) {
        this.api = api;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public Map<String, String> getParams() {
        return params;
    }

    public void setParams(Map<String, String> params) {
        this.params = params;
    }
}
